<!--suppress ALL -->
<include file="./Template/header.html" />
<link rel="stylesheet" type="text/css" href="/Template/css/updateInfo.css">
<script type="text/javascript">

	$(function() {

		//初始化页面配置
		initPage("个人资料");

		var app = new Vue({
			el: '#container',
			data: {
				info: [],
			},
			methods: {
				index: indexPage,
				updateInfo: function() {

					var nickname = $("input[name=nickname]").val();
					var sex = $("input[name=sex]").val();
					var birthday = $("input[name=birthday]").val();
					var mobile = $("input[name=mobile]").val();
					var categoryId = $("select[name=categoryId]").val();
					var hospitalName = $("input[name=hospitalName]").val();
					var doctorName = $("input[name=doctorName]").val();
                    var diagnosis = $("input[name=diagnosis]").val();
                    var city = $("input[name=city]").val();

					if(isNullOrEmpty(nickname)) {
						alert("请填写患者姓名");
						return false;
					}

					if(isNullOrEmpty(sex)) {
						alert("请选择患者性别");
						return false;
					}

					if(isNullOrEmpty(birthday)) {
						alert("请填写患者生日");
						return false;
					}

					if(isNullOrEmpty(mobile)) {
						alert("请填写联系电话");
						return false;
					}

					if(!checkPhone(mobile)) {
						alert("联系电话位数不对");
						return false;
					}

					if(isNullOrEmpty(categoryId)) {
						alert("请选择病症");
						return false;
					}

                    if(isNullOrEmpty(diagnosis)) {
                        alert("请填写诊断信息，例如‘神经性或先天性马蹄内翻足’");
                        return false;
                    }

                    if(isNullOrEmpty(city)) {
                        alert("请填写所在城市");
                        return false;
                    }

					var needDoctor = $("select[name=categoryId]").find("option:selected").attr("needDoctor");

					if(needDoctor == 1) {
						if(isNullOrEmpty(doctorName)) {
							alert("请填写医生名称");
							return false;
						}

						if(isNullOrEmpty(hospitalName)) {
							alert("请填写医院名称");
							return false;
						}
					}

					$.ajax({
						url:"/wechat/userCenter/updateInfo",
						type:"post",
						data:{
							nickname: nickname,
							sex: sex,
							mobile: mobile,
							categoryId: categoryId,
							hospitalName: hospitalName,
							doctorName: doctorName,
                            diagnosis: diagnosis,
                            city: city,
							birthday: birthday
						},
						dataType:"JSON",
						beforeSend:function(){
							$("#loadingToast").show();
						},
						complete:function(){
							$('#loadingToast').hide();
						},
						success:function(data){
							if(data.code == 200) {
								alert("保存成功");
								if(categoryId == 2){
                                    window.location.href = "/wechat/clubfoot/checkin";
								}else{
                                    window.location.href = "/wechat";
								}

							}
						},
					})

				}
			}
		})

		$(".item select").change(function() {
			var value = $(this).find("option:selected").text();
			$(this).prev().val(value);
		});

		$("input[type=date]").change(function() {
			var value = $(this).val();
			$(this).prev().val(value);
		});

	});


</script>
<div class="hint-info">
	根据药监局追溯要求,为了您的合法权益,请务必填写真实信息。
</div>
<div class="edit-content">
	<div class="item">
		<span>患者姓名</span>
		<input type="text" name="nickname" value="{$info.nickname}" placeholder="请填写您的真实姓名">
		<img class="icon-right" src="/Template/images/icon-right.png" alt="">
	</div>
	<div class="item">
		<span>患者性别</span>
		<input name="sex" type="text" value="{$info.sex}" readonly placeholder="请选择您的性别">
		<select name="sex">
			<option value="">请选择</option>
			<if condition="$info['sex'] eq '男'">
				<option value="男" selected="selected">男</option>
			<else/>
				<option value="男">男</option>
			</if>

			<if condition="$info['sex'] eq '女'">
				<option value="女" selected="selected">女</option>
			<else/>
				<option value="女">女</option>
			</if>
		</select>
		<img class="icon-right gender" src="/Template/images/icon-right.png" alt="">
	</div>

	<div class="item">
		<span>患者生日</span>
		<input id="birth-date" type="text" value="{$info.birthday}" readonly placeholder="请填写您的生日">
		<input id="birthday" name="birthday" type="date" value="{$info.birthday}">
		<img class="icon-right birth-date" src="/Template/images/icon-right.png" alt="">
	</div>
	<div class="item">
		<span>联系电话</span>
		<input type="text" name="mobile" value="{$info.mobile}" placeholder="请填写您的电话号码">
		<img class="icon-right" src="/Template/images/icon-right.png" alt="">
	</div>
	<div class="item">
		<span>病症</span>
		<input id="categoryId" type="text" value="{$ownCategory.category_name}" readonly placeholder="请选择您的症状">
		<select name="categoryId">
			<option value="">请选择</option>
			{:getCategorySelectOptionHtml($info['category_id'], 0)}
		</select>
		<img class="icon-right disease" src="/Template/images/icon-right.png" alt="">
	</div>
	<div class="item">
		<span>医生</span>
		<input type="text" name="doctorName" value="{$info.doctor_name}" placeholder="请填写您的医师姓名">
		<img class="icon-right" src="/Template/images/icon-right.png" alt="">
	</div>
	<div class="item">
		<span>医院</span>
		<input type="text" name="hospitalName" value="{$info.hospital_name}" placeholder="请填写您的医院名称">
		<img class="icon-right" src="/Template/images/icon-right.png" alt="">
	</div>
	<div class="item">
		<span>诊断</span>
		<input type="text" name="diagnosis" value="{$info.diagnosis}" placeholder="请填写您的诊断信息">
		<img class="icon-right" src="/Template/images/icon-right.png" alt="">
	</div>
	<div class="item">
		<span>所在城市</span>
		<input type="text" name="city" value="{$info.city}" placeholder="请填写您所在的城市">
		<img class="icon-right" src="/Template/images/icon-right.png" alt="">
	</div>
</div>

<div class="save-btn" v-on:click="updateInfo">
	保存
</div>

<include file="./Template/footer.html" />

